package cc3002;

public class Tamagotchi {
	protected String name;
	protected int calories;
	protected boolean isAlive;
	private HealthState health;
	public String foodSaver;
	
	private static int initCalories = 1000;
	protected static int caloriesPerActivity = 200;
	
	public Tamagotchi(String name){
		this.name = name;
		this.calories = initCalories;
		this.health=new HealthState();
		this.isAlive = true;
		this.foodSaver="00";
	}
	
	public void eat(Food food){
		assert this.isAlive : " I musn't be a zombie for this";
		if(isAlive){
			if(food.remainingBites!=0){
				this.calories += food.bite(health); 
				System.out.println(name + " has been fed with " + food.getName() + "\n");
			}
			else System.out.println(name + " is sad beacause " + food.getName() + " is not eatable anymore.\n");
			if(health.getState()==0){
				System.out.println("\nIm so sick...Im dying...arghh");
				System.out.println(name + " is resting in pieces\n");
				this.isAlive = !isAlive;
			}
		}
	}
		
	public void play(){
		assert this.isAlive : " I musn't be a zombie for this";
		if(isAlive){
			System.out.println(name + " is playing\n");
			
			consumeCalories();
		}
	}
	
	public void viewStatistics(){
		if(isAlive) {
			System.out.println("The tamagotchi " + name + " has:");
			System.out.println("  calories:" + calories + " left");
			System.out.println("  Health status: "+health.toString()+"\n");
			System.out.println("  "+health.getFoodSaver());
		} else {
			System.out.println("The poor " + name + " passed away for a better life\n");
		}
	}
	
	public void die(){
		this.viewStatistics();
		
		if(calories > 0){
			System.out.println(name + ": Hey! i want to live, don't kill me!\n");
			consumeCalories();
		} else {
			System.out.println("\nIt's my fate hour, you didn't feed me");
			System.out.println(name + " is resting in pieces\n");
			
			this.isAlive = !isAlive;
		}
	}
	
	protected void consumeCalories(){
		this.calories -= caloriesPerActivity*health.getCCMultiplier();
	}
	
}